package com.thread;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

public class ThreadAtomicInteger013 {

    AtomicInteger count = new AtomicInteger(0);

    void m(){
        for(int i=0;i<100;i++){
            count.getAndIncrement();
        }
    }

    public static void main(String[] args) {
        ThreadAtomicInteger013 t = new ThreadAtomicInteger013();

        List<Thread> list = new ArrayList<>();

        for(int i=0;i<10;i++){
            list.add(new Thread(t::m,"i="+i));
        }

        list.forEach(thread -> {thread.start();});

        list.forEach((thread -> {
            try {
                thread.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }));

        System.out.println(t.count);
    }
}
